using Common.Core.Configuration;
using Microsoft.Practices.Unity;

namespace Common.Unity.Configuration
{
	public class UnityConfigurationContainer : UnityConfigurationContainer<UnityConfigurationContainer>
	{}

	public class UnityConfigurationContainer<InstanceType> : ConfigurationContainer<InstanceType> where InstanceType : ConfigurationContainer<InstanceType>, new()
	{
		public IUnityContainer DefaultContainer
		{
			get { return defaultContainer ?? ( defaultContainer = Get<IUnityContainer>() ?? Get<Microsoft.Practices.Unity.UnityContainer>() ); }
		}	IUnityContainer defaultContainer;

		public static IUnityContainer Container
		{
			get { return container; }
		}	static readonly IUnityContainer container = Instance.Get<IUnityContainer>() ?? Instance.Get<Microsoft.Practices.Unity.UnityContainer>();

		protected override object ResolveService(System.Type type, string name)
		{
			var result = DefaultContainer.Resolve( type, name );
			return result;
		}
	}
}